import { request } from '../network/request.js'

export default {
    namespaced: true,
    state: {
        arr: [],
        array:[],
        page: {
            currentPage: 1,
            pageSize: 3 ,
            total:5
          },
    },
    mutations: {
        changearr(state, rows) {
            // console.log(arr,state.arr)
            state.arr = rows
        },
        changearray(state, rows) {
            // console.log(arr,state.arr)
            state.array = rows
        },
        changetotal(state, total) {
            state.page.total = total
            // console.log(state.pageTotal)
        }
    },
    actions: {
        //渲染
        async getAdmin(context,{ currentPage,pageSize }) {
            console.log({ currentPage,pageSize })
            const msg = await request({
                url: "/admins/getAdmin",
                method: "post",
                data: {
                    currentPage:currentPage,
                    pageSize:pageSize
                  }
            });
            console.log(msg)
            // console.log( currentPage,pageSize)
            context.commit('changearr', msg.rows)//因为不能在action中修改，所以将数据传到mutations中再修改
            context.commit('changetotal', msg.total)//因为不能在action中修改，所以将数据传到mutations中再修改
        },
        //冻结
        // async frozen(context, { _id }) {
        //     const msg = await request({
        //         url: "/admins/frozen",
        //         method: "post",
        //         data: {
        //             _id
        //         }
        //     });
        //     console.log(msg)
        // },
        //新增
        async addAdmin(context, { name, stock, shopid, bool, pirce, img }) {
            console.log(name, stock, shopid, bool, pirce, img)
            const msg = await request({
                url: "/admins/addAdmin",
                method: "post",
                data: {
                    name, stock, shopid, bool, pirce, img
                }
            });
            return msg
            // console.log(msg)
        },
        //删除
        async delAdmin(context, { _id }) {
            console.log({ _id })
            const msg = await request({
                url: "/admins/delAdmin",
                method: "post",
                data: {
                    _id
                }
            });
            return msg
            console.log(msg)
        },
        //查找
        async queryAdmin(context, { choose, value }) {
            const msg = await request({
                url: "/admins/queryAdmin",
                method: "post",
                data: {
                    choose, value
                }
            });
            context.commit('changearr', msg.rows.data)
        },
        //修改
        async reviseAdmin(context, { _id, shopid, name, pirce, bool, stock, img }) {
            const msg = await request({
                url: "/admins/reviseAdmin",
                method: "post",
                data: { _id, shopid, name, pirce, bool, stock, img }
            });
            return msg
            // context.commit('changearr', msg.rows.data)
        },
          //超级管理员 管理
          async getSuperAdmin(context, { currentPage, pageSize }) {
            // console.log({ currentPage, pageSize })
            const msg = await request({
                url: "/admins/getSuperAdmin",
                method: "post",
                data: {
                    currentPage: currentPage,
                    pageSize: pageSize
                }
            });
            console.log(msg)
            // console.log( currentPage,pageSize)
            context.commit('changearray', msg.rows)//因为不能在action中修改，所以将数据传到mutations中再修改
            // context.commit('changetotal', msg.total)//因为不能在action中修改，所以将数据传到mutations中再修改
        },
        //轮播图管理 渲染
        async getPicture(context ) {
            // console.log({ currentPage, pageSize })
            const msg = await request({
                url: "/admins/getPicture",
                method: "post",
            });
            console.log(msg.rows)
            // console.log( currentPage,pageSize)
            context.commit('changearray', msg.rows)//因为不能在action中修改，所以将数据传到mutations中再修改
            // context.commit('changetotal', msg.total)//因为不能在action中修改，所以将数据传到mutations中再修改
        },
        //添加轮播图
        async addPicture(context,{img} ) {
            // console.log({ currentPage, pageSize })
            const msg = await request({
                url: "/admins/addPicture",
                method: "post",
                data:{
                    img
                }
            });
            console.log(msg)
            // console.log( currentPage,pageSize)
            // context.commit('changearray', msg.rows)//因为不能在action中修改，所以将数据传到mutations中再修改
            // context.commit('changetotal', msg.total)//因为不能在action中修改，所以将数据传到mutations中再修改
        },
    },



}